using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Reap.AzureResource.Model.Models.Mapping
{
    public class ResourceMap : EntityTypeConfiguration<Resource>
    {
        public ResourceMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.ResourceName)
                .HasMaxLength(200);

            this.Property(t => t.ResourcePath)
                .HasMaxLength(200);

            this.Property(t => t.FileSize)
                .HasMaxLength(30);

            // Table & Column Mappings
            this.ToTable("Resource");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.LocationId).HasColumnName("LocationId");
            this.Property(t => t.ResourceName).HasColumnName("ResourceName");
            this.Property(t => t.ResourcePath).HasColumnName("ResourcePath");
            this.Property(t => t.UploadStartTime).HasColumnName("UploadStartTime");
            this.Property(t => t.UploadEndTime).HasColumnName("UploadEndTime");
            this.Property(t => t.FileSize).HasColumnName("FileSize");
            this.Property(t => t.Fstatus).HasColumnName("Fstatus");

            // Relationships
            this.HasOptional(t => t.Location)
                .WithMany(t => t.Resources)
                .HasForeignKey(d => d.LocationId);

        }
    }
}
